package com.it.sun.learning001.processor;

import com.it.sun.learning001.base.Car;
import com.it.sun.learning001.base.EnhanceCar;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanClassLoaderAware;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.stereotype.Component;

/**
 * @ClassName com.it.sun.learning001.processor.BeanPostProcessorBean
 * @Author sunmannian
 * @Date 2021/6/16 15:31
 * @Version V1.0
 * Description  <请输入一句话描述该类功能>
 * Copyright (C) 北京中电兴发科技有限公司  since 2021/6/16
 */
@Component
public class BeanPostProcessorImpl implements BeanPostProcessor, BeanClassLoaderAware {

	private ClassLoader classLoader;

	@Override
	public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
		if (bean instanceof Car) {
			Car car = (Car) bean;
			car.setCapacity(10);
			car.setTrademark("audi");
		}
		return bean;
	}

	@Override
	public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
//		if (bean instanceof Car) {
//			Car car = (Car) bean;
//			EnhanceCar delegateCar = new EnhanceCar(car);
//			return delegateCar.getEnhancerCar();
//		}
		return bean;
	}

	@Override
	public void setBeanClassLoader(ClassLoader classLoader) {
		this.classLoader = classLoader;
	}
}



